using UnityEngine;
using QFramework;
using UnityEditor.UIElements;

namespace Projectsurviva
{
	public partial class magnet : ViewController
	{
        public void OnTriggerEnter2D(Collider2D collision)
        {
            if(collision.GetComponent<Collectcircle>())
            {
                foreach (var item in FindObjectsByType<Exp>(FindObjectsInactive.Exclude,FindObjectsSortMode.None))
                {
                    ActionKit.OnUpdate.Register(() =>
                    {
                        var player = Play.Default;
                        if(player)
                        {
                            var dirction = player.transform.position - item.transform.position;
                            item.transform.Translate(dirction.normalized * Time.deltaTime * 3);
                        }
                    }).UnRegisterWhenGameObjectDestroyed(item);
                }
                
                AudioKit.PlaySound("_get_all_exp");

                this.DestroyGameObjGracefully();
            }
        }
    }
}
